package hn.sigit.view.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

@Name("uiValidators")
@Scope(value = ScopeType.APPLICATION)
@AutoCreate
public class UIValidators {
	public void validateNotNull(FacesContext context, UIComponent toValidate, Object value) {
		String message = "Valor requerido";
		
		if (value == null) {
			((UIInput) toValidate).setValid(false);
			context.addMessage(toValidate.getClientId(context), new FacesMessage(message));
		}
	}
}
